<?php
/**
 * Created by JetBrains PhpStorm.
 * User: root
 * Date: 13-12-25
 * Time: 下午3:36
 * To change this template use File | Settings | File Templates.
 */
namespace Common\Org\Email\Driver;
use Common\Org\Email\Email;
use Common\Org\Net\PHPMailer;

class EmailSmtp extends Email {
    protected $config = array();

    //初使化
    public function __construct($config) {
        if(!empty($config)) {
            $this->config = $config;
        }
    }

    /**
     * 发送邮件方法
     */
    protected function send() {
        $mail             = new PHPMailer();
        $mail->IsSMTP(); 					   // telling the class to use SMTP
        $mail->SMTPDebug  = false;             // enables SMTP debug information (for testing)
        // 1 = errors and messages
        $mail->CharSet = 'UTF-8';                           // 2 = messages only
        $mail->SMTPAuth   = true;
        $mail->Host       = $this->config['url']; 				//  SMTP 服务器
        $mail->SMTPAuth = true;
        $mail->Port       = 25;
        // set the SMTP port for the GMAIL server
        $mail->Username   = $this->config['account'];   		// "xxxx@163.com";    SMTP用户名
        $mail->Password   = $this->config['password'];     		// SMTP密码
        $mail->SetFrom($this->config['send_email'], $this->config['sender']);		// 发件人地址 , 发件人
        $mail->AddReplyTo($this->config['reply_email'], $this->config['replier']);				// 回复地址

        $mail->Subject   = $this->them;           				// 邮件主题
        $mail->MsgHTML($this->body);								// 邮件正文
        //var_dump($mail);exit;
        //var_dump($mail);exit;
        //$mail->AltBody    = L('pleaseread'); // optional, comment out and test
        //群发多个邮箱
        foreach($this->email as $key => $val) {
            $mail->ClearAddresses() ;
            $mail->AddAddress($val, $val);				//接收地址， 接收人
            $_return[$key] = $mail->Send();
        }

        return true;
    }
}